class e0 {
    constructor(l) {
        En(this, "_apiKey"),
        En(this, "_prevSymbolMarket"),
        En(this, "_ws"),
        this._apiKey = l
    }
    async searchSymbols(l) {
        return await ((await (await fetch(`http://localhost:8086/stock_data?code=${this._apiKey}&active=true`)).json()).results || []).map(a=>({
            ticker: a.ticker,
            name: a.name,
            shortName: a.ticker,
            market: a.market,
            exchange: a.primary_exchange,
            priceCurrency: a.currency_name,
            type: a.type,
            logo: ""
        }))
    }
    async getHistoryKLineData(l, a, v, m) {
        var rs = await (await fetch(`http://localhost:8086/stock_data?code=${this._apiKey}`)).json();
        console.log(rs);
        if (rs.queryCount == rs.resultsCount)
        {
            my_more = false;
        }
        else
        {
            my_more = true;
        }
        return await (rs.results || []).map(C=>({
            timestamp: C.t,
            open: C.o,
            high: C.h,
            low: C.l,
            close: C.c,
            volume: C.v,
            turnover: C.vw
        }))
    }
    subscribe(l, a, v) {
        var m, C;
        this._prevSymbolMarket !== l.market ? ((m = this._ws) == null || m.close(),
        this._ws = new WebSocket(`wss://delayed.polygon.io/${l.market}`),
        this._ws.onopen = ()=>{
            var S;
            (S = this._ws) == null || S.send(JSON.stringify({
                action: "auth",
                params: this._apiKey
            }))
        }
        ,
        this._ws.onmessage = S=>{
            var b;
            const A = JSON.parse(S.data);
            A[0].ev === "status" ? A[0].status === "auth_success" && ((b = this._ws) == null || b.send(JSON.stringify({
                action: "subscribe",
                params: `T.${l.ticker}`
            }))) : "sym"in A && v({
                timestamp: A.s,
                open: A.o,
                high: A.h,
                low: A.l,
                close: A.c,
                volume: A.v,
                turnover: A.vw
            })
        }
        ) : (C = this._ws) == null || C.send(JSON.stringify({
            action: "subscribe",
            params: `T.${l.ticker}`
        })),
        this._prevSymbolMarket = l.market
    }
    unsubscribe(l, a) {}
}